package org.example.week10;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import java.io.IOException;

@WebServlet("/user-manage")
public class AdminServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
        throws IOException {
        
        UserDAO userDAO = new UserDAO();
        int userId = Integer.parseInt(request.getParameter("id"));
        User user = userDAO.getUserById(userId);
        
        int newPriv = (user.getPriv() == 3) ? 2 : 3;
        userDAO.updateUser(new User(userId, user.getName(), user.getPwd(), newPriv));
        
        response.sendRedirect("show-userList.jsp");
    }
}